package com.hk.blog;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;


/**
 * @author Kevin
 */
@Slf4j
@SpringBootApplication
public class BlogApplication /*implements CommandLineRunner*/ {

    public static void main(String[] args) {
        try {
            SpringApplication.run(BlogApplication.class, args);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }

//    @Autowired
//    private ArticleInfoRepository articleInfoRepository;
//
//    @Autowired
//    private ArticleInfo2Repository articleInfo2Repository;
//
//    @Override
//    public void run(String... args) {
//        new Thread(() -> {
//            var list = articleInfoRepository.findAll();
//            int size = list.size();
//            ArticleInfo2 articleInfo;
//            for (int i = 0; i < 3_000_000; i++) {
//                ArticleInfo info = list.get(RandomUtils.nextInt(0, size));
//                articleInfo = new ArticleInfo2()
//                        .setUserId(info.getUserId())
//                        .setBrowseNum(info.getBrowseNum())
//                        .setCategoryId(info.getCategoryId())
//                        .setProtect(info.getProtect())
//                        .setTitle(info.getTitle())
//                        .setContent(info.getContent());
//                articleInfo2Repository.save(articleInfo);
//
//            }
//
//        }).start();
//    }

//    @Component
//    public static class InitCommandLineRunner implements CommandLineRunner {
//
//        @Autowired
//        private ArticleInfoService articleInfoService;
//        //
//        @Autowired
//        private EsArticleInfoRepository esArticleInfoRepository;
//
//        //
//        @Override
//        public void run(String... args) {
//            esArticleInfoRepository.deleteAll();
//            var list = StreamSupport.stream(articleInfoService.findAll().spliterator(), false).map(item -> {
//                var esArticleInfo = new EsArticleInfo()
//                        .setBrowseNum(item.getBrowseNum())
//                        .setCategoryId(item.getCategoryId())
//                        .setContent(item.getContent())
//                        .setUserId(item.getUserId())
//                        .setTitle(item.getTitle())
//                        .setLastModifiedDate(item.getLastUpdateDate());
////                        .setLastUpdateDate(DateTimeUtils.localDateTimeToString(item.getLastUpdateDate(), DatePattern.YYYY_MM_DD_HH_MM_SS));
//                esArticleInfo.setId(item.getId().toString());
//                return esArticleInfo;
//            }).collect(Collectors.toList());
//            esArticleInfoRepository.saveAll(list);
//            if (!list.isEmpty()) {
//                Optional<EsArticleInfo> info = esArticleInfoRepository.findById(list.get(0).getId());
//                log.debug("result:{}", JsonUtils.serialize(info.orElse(null), true));
//            }
//        }
//    }

}
